package initialize

import (
	"github.com/panjf2000/ants/v2"
	"transfer-service/internal/conf"
	"transfer-service/internal/global"
)

func InitAnts(c *conf.Ants) {
	pool, err := ants.NewPool(
		int(c.Size),
		ants.WithExpiryDuration(c.ExpiryDuration.AsDuration()), // 设置过期时间
		ants.WithPreAlloc(c.PreAlloc),                          // 是否内存预分配
		ants.WithMaxBlockingTasks(int(c.MaxBlockingTasks)),     // 设置最大阻塞任务数
		ants.WithNonblocking(c.Nonblocking),                    // 是否非阻塞
		ants.WithDisablePurge(c.DisablePurge),                  // 是否禁用清除
	)
	if err != nil {
		return
	}
	global.APOOL = pool
}
